package sskj.regulatory.presentation.screen.main

import android.os.Bundle
import com.qmui.arch.QMUIFragment
import sskj.regulatory.R
import sskj.regulatory.arch.BackHandledInterface
import sskj.regulatory.presentation.base_mvp.base.BaseActivity
import javax.inject.Inject


class MainActivity : BaseActivity<MainContract.View, MainContract.Presenter>(), MainContract.View, BackHandledInterface {


    private val TAG = "MainActivity"

    private var mBackHandedFragment: QMUIFragment? = null

    override fun setSelectedFragment(selectedFragment: QMUIFragment?) {
        this.mBackHandedFragment = selectedFragment;
    }

    @Inject
    lateinit var mPresenter: MainPresenter

    override fun injectDependencies() {
        activityComponent.inject(this)
    }

    override fun initPresenter() = mPresenter


    override fun getContextViewId(): Int {
        return R.id.regulatory_main
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        if (savedInstanceState == null) {

            supportFragmentManager
                    .beginTransaction()
                    .setCustomAnimations(sskj.regulatory.arch.R.anim.scale_enter, R.anim.slide_still,
                            sskj.regulatory.arch.R.anim.slide_still, R.anim.scale_exit)
                    .add(contextViewId,  MainFragment(), MainFragment::class.java.simpleName)
                    .addToBackStack(MainFragment::class.java.simpleName)
                    .commit()
        }
    }

    override fun onBackPressed() {
        when (mBackHandedFragment?.onBackPressed()) {
            true -> {
                super.onBackPressed()
            }
        }
    }

}